/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package authentication;

import data.email.AccountType;

/**
 * Enum pro uchování a propojení údajů o typu šifrování, použitém protokolu a příslušném portu
 * @author Pavel
 */
public enum AuthenticationPort {

    SMTP_SSL(465, EncryptionType.SSL, AccountType.SMTP),
    SMTP_TLS(587, EncryptionType.TLS, AccountType.SMTP),
    SMTP_DEFAULT(25, EncryptionType.none, AccountType.SMTP),
    IMAP_SSL(993, EncryptionType.SSL, AccountType.IMAP),
    IMAP_TLS(143, EncryptionType.TLS, AccountType.IMAP),
    IMAP_DEFAULT(143, EncryptionType.none, AccountType.IMAP),
    POP_SSL(995, EncryptionType.SSL, AccountType.POP3),
    POP_DEFAULT(110, EncryptionType.none, AccountType.POP3);
    private final int port;
    private final EncryptionType enType;
    private final AccountType accType;

    private AuthenticationPort(int p, EncryptionType et, AccountType at) {
        port = p;
        enType = et;
        accType = at;
    }

    public int getPort() {
        return port;
    }

    public EncryptionType getEnType() {
        return enType;
    }

    public AccountType getAccType() {
        return accType;
    }

    public static AuthenticationPort findPort(EncryptionType et, AccountType at) {
        for (AuthenticationPort port : AuthenticationPort.values()) {
            if (port.getAccType().equals(at) && port.getEnType().equals(et)) {
                return port;
            }
        }
        return null;
    }

    public static AuthenticationPort findPort(int portNumber, AccountType at) {
        for (AuthenticationPort port : AuthenticationPort.values()) {
            if (port.getAccType().equals(at) && port.getPort() == portNumber) {
                return port;
            }
        }
        return null;
    }
}
